package com.ljw.common.utils;

import com.ljw.common.constant.AuthServiceConstant;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class GetCookieUtils {

    public static String getMemberIdFormCookie(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        if (cookies != null && cookies.length > 0){
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(AuthServiceConstant.LOGIN_USER)){
                    String jwtToken = cookie.getValue();
                    String memberId = JwtUtils.getMemberIdByJwtToken(jwtToken);
                    return memberId;
                }
            }
        }
        return null;
    }

}
